package com.das.mechanic_base.app;

import com.das.mechanic_base.BuildConfig;
import com.das.mechanic_base.bean.common.LocaleBean;
import com.das.mechanic_base.utils.LanguageUtiles;
import com.das.mechanic_base.utils.SpHelper;
import com.das.mechanic_base.utils.X3StringUtils;
import com.yhao.floatwindow.IFloatWindow;

import java.util.Locale;

public class X3Constent {

//    @包红旭 @陈思  服务项目详情页(车主和技师) serve/serve-detail.html?sn=sn&carId=carId

    public static String VERSION_SUFFIX = "";

    // 是否是开放的sdk
    public static String IS_OPEN_SDK = "IS_OPEN_SDK";

    // 技师的配置
    public static String BRAND_MECHANIC_CONFIG = "BRAND_MECHANIC_CONFIG";

    // 施工单是否首次进入
    public static String WORK_FIRST_SHOW_NOTICE = "WORK_FIRST_SHOW_NOTICE";

    // 施工单是否首次提交
    public static String WORK_FIRST_SUBMIT_NOTICE = "WORK_FIRST_SUBMIT_NOTICE";

    // 弱提醒
    public static final String WEAK_UPDATE = "WEAK_UPDATE";

    // 强提醒
    public static final String STRONG_UPDATE = "STRONG_UPDATE";

    // 强更
    public static final String FORCED_UPDATE = "FORCED_UPDATE";

    // 默认的brand icon
    public static String BRAND_ICON = "BRAND_ICON";

    //  直播设备名称
    public static String LIVE_PHONE_NAME = "LIVE_PHONE_NAME";

    // 工作模式
    public static String WORK_MODEL = "WORK_MODEL";

    // 是否关闭腾讯im登录 关闭单点登录
    public static String TENCENT_IM_CLOSE_LOGIN = "TENCENT_IM_CLOSE_LOGIN";

    /**
     * 账号偏好设置的相机
     * 0 快速相机
     * 1 快速录像
     * 2 完整模式
     */
    public static String QUICK_CAMERA_MODE = "QUICK_CAMERA_MODE";

    /**
     * 检测拍照顺序
     *
     * 检测项的拍照是在答题前还是在答题后，ture 在前，false 在后
     */
    public static String ALONE_CAMERA_ORDER = "ALONE_CAMERA_ORDER";

    /**
     * 开启直播的二维码
     */
    public static String LIVE_AES = "LIVE_AES";

    /**
     * 直播二维码用到的地址
     */
    public static final String BASE_URL_LIVE_SAVE = "BASE_URL_LIVE";

    /**
     * 共享检测条目的请求吗
     */
    public static final int REQUEST_CODE_PREVIEW = 30001;

    // 是否是从首页来的
    public static final String IS_LOGIN = "IS_LOGIN";

    // 默认的门店id
    public static final String DEFAULT_BRAND_IT = "DEFAULT_BRAND_IT";

    /**
     * 从相册获取
     */
    public static final int CODE_GALLERY_REQUEST = 0xa0;

    /**
     * 从相机获取
     */
    public static final int CODE_CAMERA_REQUEST = 0xa1;

    /**
     * alone添加服务之后刷新页面
     */
    public static final int CODE_ALONE_ADD_SERVICE_REQUEST = 0xa6;

    /**
     * alone页面修改里程和日期
     */
    public static final int CODE_ALONE_CHANGE_NEED_UPDATE = 0xa7;

    /**
     * alone是否刷新新数据
     */
    public static final int CODE_ALONE_ADD_SERVICE_REFRESH = 0xa8;

    /**
     * 传回标签 用以计算选中哪道题目
     */
    public static final int CODE_ALONE_IMAGE_TO_QUESTION = 0xa9;

    /**
     * 用户密码
     */
    public static final String USER_PASSWORD = "USER_PASSWORD";

    public static final int CODE_CAMERA_VIN_REQUEST = 307;
    public static final int ALONE_SIGN_REQUEST = 308;

    /**
     * 当前正在录制录音的地址
     */
    public static final String CURRENT_MAKE_RECORD_PATH = "CURRENT_MAKE_RECORD_PATH";

    // 英国线上
    public static String baseUrl = "https://uk.autox3.com/mechanic/api-v1/";

    // cn
    public static final String zhBaseUrl = "https://cn.autox3.com/mechanic/api-v1/";

    // us
    public static final String usBaseUrl = "https://us.autox3.com/mechanic/api-v1/";

    // tw
    public static final String twBaseUrl = "https://tw.autox3.com/mechanic/api-v1/";

    //germany
    public static final String deBaseUrl = "https://de.autox3.com/mechanic/api-v1/";

    //Malaysia
    public static final String myBaseUrl = "https://my.autox3.com/mechanic/api-v1/";

    //Ierland
    public static final String ieBaseUrl = "https://ie.autox3.com/mechanic/api-v1/";

    /**
     * local服务器后缀
     */
    public static final String BASE_URL_ADDRESS = "/mechanic/api-v1/";

    /**
     * 存储请求到的服务器地址
     */
    public static final String BASE_URL_SAVE = "BASE_URL";

    // 英国国内地址
    public static String SERVICE_URL = "https://h5uk.autox3.com/mechanic/";

    // zh
    public static final String ZH_SERVICE_URL = "https://h5cn.autox3.com/mechanic/";

    // us
    public static final String US_SERVICE_URL = "https://h5us.autox3.com/mechanic/";

    // tw
    public static final String TW_SERVICE_URL = "https://h5tw.autox3.com/mechanic/";

    //de
    public static final String DE_SERVICE_URL = "https://h5de.autox3.com/mechanic/";

    //ml
    public static final String MY_SERVICE_URL = "https://h5my.autox3.com/mechanic/";

    //Ierland
    public static final String IE_SERVICE_URL = "https://h5ie.autox3.com/mechanic/";

    /**
     * local服务器后缀
     */
    public static final String BASE_SERVICE_URL_ADDRESS = "/mechanic/";

    /**
     * 存储请求到的服务器地址
     */
    public static final String BASE_SERVICE_URL_SAVE = "BASE_SERVICE_URL";

    /**
     *
     */
    public static final String AREA_CODE = "AREA_CODE";

    /**
     * 里程单位
     */
    public static final String MILEAGEUNIT = "MileageUnit";

    /**
     * 货币单位描述
     */
    public static final String MONEYUNIT = "MoneyUnit";

    /**
     * 货币单位
     */
    public static final String MONEYCODE = "MoneyCode";

    // 首页车辆详情页
    public static final String HOME_CAR_DETAIL_URL = "crm/vehicle/vehicle-detail.html?carId=";

    //保养计划
    public static final String HOME_CAR_PLAN_DETAIL_URL = "car-detail/plan/plan.html?carId=";

   // 车况问题  /car-detail/problem/problem.html?carId=1
   public static final String HOME_CAR_Problem_DETAIL_URL = "car-detail/problem/problem.html?carId=";


    // 首页客户详情页
    public static final String HOME_CUSETOM_DETAIL_URL = "crm/customer/customer-detail.html?carOwnerUserId=";

    // 初检报告
    public static final String HOME_FIRST_ALONE_REPORT = "inspection/detail/index.html?id=";

    // 首页接车单
    public static final String HOME_GET_GAR_DETAIL_URL = "receive/receive-detail.html?id=";

    // 首页已经完成的施工单详情（除检测）
    public static final String HOME_FINISH_DETAIL_URL = "construction/detail/detail.html?";

    //  服务项目详情页 sn=sn&carId=carId;
    public static final String SERVICE_INFO_PAGE_URL = "serve/serve-detail.html?sn=";

    // 订单未支付详情
    public static final String ORDER_NOT_PAY_URL = "msg/order-detail.html?id=";

    // 加入购物车
    public static final String ADD_SHOP_URL = "msg/recommend-detail.html?id=";

    // 安排施工成功
    public static final String SAVE_WORK_SUCCESS = "receive/success/success.html";

    // 查看报价单详情
    public static final String CHECK_RECEIVE_QUOTATION = "quote/index.html?id=";

    /**
     * 查看施工单详情
     */
    public static final String MAIN_TAIN_ADD_WORK = "receive/add-work/add-work.html?";

    // 施工完成之后查看专属保养计划
    public static final String WORK_FINSH_CHECK_PLAN = "cycle/cycle-check.html?";

    // 询价审核详情
    public static final String XUN_JIA_SERVICE_URL = "msg/inquiry-detail.html?id=";

    // 用户协议
    public static final String USER_AGREEMENT = "register/file/agreement.html?source=app";

    // 隐私协议
    public static final String PRIVACY_AGREEMENT = "register/file/privacy.html?source=app";

    public static final String HOME_FINISH_DETAIL_MAIN_URL = "report/report-index.html?";

    // 首页预约单
    public static final String HOME_APPOINT_DETAIL_URL = "appointment/appointment-detail.html?id=";

    // 我的页面 施工记录
    public static final String MINE_WORK_DETAIL_URL = "construction/construction-record.html";

    // 我的页面 预约记录
    public static final String MINE_APPIONT_DETAIL_URL = "appointment/appointment-record.html";

    // 我的页面 我的收入
    public static final String MINE_WORK_RECOME_URL = "self/income.html";

    // 我的页面查看有效检测和常见异常
    public static final String MINE_SHOW_DETAIL = "statistics/situation/situation.html";

    /**
     * 施工结束url   https://h5dev.autox3.cn/mechanic/cycle/serve-adjust.html?workBaseId=109
     */
    public static final String MAIN_NEW_SIVE_URL = "cycle/serve-adjust.html?workBaseId=";

    /**
     * 分享步序图url  https://h5test.autox3.com/wxh5/step/index.html?id=9636
     */
    public static final String SHARE_STEP_URL = "wxh5/step/index.html?id=";

    /**
     * 分享 施工报告小程序 默认网页链接
     * https://h5cntest.autox3.com/wxh5/construction/detail/detail.html?id=245187&timestamp=1645510159667
     */
    public static final String SHARE_MINI_URL = "wxh5/construction/detail/detail.html?id";

    /**
     * 分享检测报告 小程序 默认网页链接
     * https://h5cntest.autox3.com/wxh5/construction/detail/detail.html?id=245187&timestamp=1645510159667
     */
    public static final String SHARE_ALONE_MINI_URL = "wxh5/report/report-index.html?workBaseId=";

    /**
     * 检测结束url
     */
    public static final String MAIN_NEW_TAIN_URL = "cycle/cycle-adjust.html?workBaseId=";

    /**
     * 车辆详情中的属性 lottie下面的
     */
    public static final String BOTTOM_SHOW_LOTTIE = "crm/vehicle/vehicle-inform.html?carId=";

    /**
     * 腾讯云推送
     */
    public static final int TEST_LOCAL_NOTIFICATION = 1;
    public static final int TEST_NOTIFICATION = 2;
    public static final int TEST_SET_TAG = 3;
    public static final int TEST_DEL_TAG = 4;
    public static final int TEST_SET_ACCOUNT = 5;
    public static final int TEST_DEL_ACCOUNT = 6;

    public static final String LOCAL_NOTIFICATION_TITLE = "localtest";
    public static final String TEST_TAG_NAME = "DiagnosisTag";

    /**
     * app更新
     */
    // 强提醒存储时间年月日 实现一天弹出一次
    public static final String STRONG_REMINDER_TIME = "STRONG_REMINDER_TIME";

    // 弱提醒存储版本号 只提醒一次
    public static final String WEAK_REMINDER_APP = "WEAK_REMINDER_APP";

    //  强提醒 红点提醒
    public static final String STRONG_REMINDER_RED = "STRONG_REMINDER_RED";

    // 弱提醒  红点点击提醒
    public static final String WEAK_REMINDER_CLICK = "WEAK_REMINDER_CLICK";

    // 不提醒 红点点击提醒
    public static final String NO_REMINDER_CLICK = "NO_REMINDER_CLICK";

    /**
     * MOST_HIGH 100
     * HIGH 75
     * MIDDLE 50
     * LOW 25
     */
    public static final String CAMERA_QUALITY = "CAMERA_QUALITY";

    /**
     * 存储localURL和localH5Url
     */
    public static void saveBaseUrl(String baseUrl,String baseServiceUrl) {
        if (X3StringUtils.isEmpty(baseUrl) || X3StringUtils.isEmpty(baseServiceUrl)) {
            return;
        }
        SpHelper.saveData(X3Constent.BASE_SERVICE_URL_SAVE,baseServiceUrl);
        SpHelper.saveData(X3Constent.BASE_URL_SAVE,baseUrl);
    }

    /**
     * 获取默认区号
     */
    public static String getDefaultAreaCode() {
        LocaleBean appLocale = LanguageUtiles.getAppLocale(LanguageUtiles.appContext);
        if(appLocale.locale.getLanguage().equalsIgnoreCase("en")
                && appLocale.locale.getCountry().equalsIgnoreCase("US")) {
            return "+1";

        }else if (appLocale.locale.getLanguage().equalsIgnoreCase("zh")
                && appLocale.locale.getCountry().equalsIgnoreCase("CN")) {
            return "+86";

        }else if (appLocale.locale.getLanguage().equalsIgnoreCase("zh")
                && appLocale.locale.getCountry().equalsIgnoreCase("TW")) {
            return "+886";

        } else if(appLocale.locale.getLanguage().equalsIgnoreCase("en")
                && appLocale.locale.getCountry().equalsIgnoreCase("ie")) {
            return "+353";

        } else if(appLocale.locale.getLanguage().equalsIgnoreCase("de")
                && appLocale.locale.getCountry().equalsIgnoreCase("de")) {
            return "+49";

        } else if(appLocale.locale.getLanguage().equalsIgnoreCase("en")
                && appLocale.locale.getCountry().equalsIgnoreCase("my")) {
            return "+60";

        } else {
            return "+44";
        }
    }

    //根据区号获取地址
    public static String getBaseUrlByAreaCode() {
        String areaCode = (String) SpHelper.getData(X3Constent.AREA_CODE, X3Constent.getDefaultAreaCode());
         if("+1".equals(areaCode)){
             return usBaseUrl;
         } else if("+86".equals(areaCode)){
             return  zhBaseUrl;
         }else if("+886".equals(areaCode)){
             return twBaseUrl;
        }else if("+49".equals(areaCode)){//de
             return deBaseUrl;
         }else if("+60".equals(areaCode)){
             return myBaseUrl;
        }else if("+353".equals(areaCode)){
             return ieBaseUrl;
        }  else {
             return baseUrl;
         }
    }

    /**
     * 根据区号获取服务器地址
     * @return
     */
    public static String getBaseServiceUrlByAreaCode() {
        String areaCode = (String) SpHelper.getData(X3Constent.AREA_CODE, X3Constent.getDefaultAreaCode());
        if("+1".equals(areaCode)){
            return US_SERVICE_URL;
        } else if("+86".equals(areaCode)){
            return  ZH_SERVICE_URL;
        }else if("+886".equals(areaCode)){
            return TW_SERVICE_URL;
        }else if("+49".equals(areaCode)){//de
            return DE_SERVICE_URL;
        }else if("+60".equals(areaCode)){
            return MY_SERVICE_URL;
        }else if("+353".equals(areaCode)){
            return IE_SERVICE_URL;
        }  else {
            return SERVICE_URL;
        }
    }

    /**
     * 登录之前返回机器语言
     */
    public static String getDefaultLogineAreaCode() {
        Locale appLocale = LanguageUtiles.getSystemLocale();
        if(appLocale.getLanguage().equalsIgnoreCase("en")
                && appLocale.getCountry().equalsIgnoreCase("US")) {
            SpHelper.saveData(X3Constent.BASE_SERVICE_URL_SAVE, X3Constent.US_SERVICE_URL);
            return "+1";
        }else if (appLocale.getLanguage().equalsIgnoreCase("zh")
                && appLocale.getCountry().equalsIgnoreCase("CN")) {
            SpHelper.saveData(X3Constent.BASE_SERVICE_URL_SAVE, X3Constent.ZH_SERVICE_URL);
            return "+86";

        }else if (appLocale.getLanguage().equalsIgnoreCase("zh")
                && appLocale.getCountry().equalsIgnoreCase("TW")) {
            SpHelper.saveData(X3Constent.BASE_SERVICE_URL_SAVE, X3Constent.TW_SERVICE_URL);
            return "+886";
        } else if(appLocale.getLanguage().equalsIgnoreCase("en")
                && appLocale.getCountry().equalsIgnoreCase("ie")) {
            SpHelper.saveData(X3Constent.BASE_SERVICE_URL_SAVE, X3Constent.IE_SERVICE_URL);
            return "+353";
        } else if(appLocale.getLanguage().equalsIgnoreCase("de")
                && appLocale.getCountry().equalsIgnoreCase("de")) {
            SpHelper.saveData(X3Constent.BASE_SERVICE_URL_SAVE, X3Constent.DE_SERVICE_URL);
            return "+49";
        } else if(appLocale.getLanguage().equalsIgnoreCase("en")
                && appLocale.getCountry().equalsIgnoreCase("my")) {
            SpHelper.saveData(X3Constent.BASE_SERVICE_URL_SAVE, X3Constent.MY_SERVICE_URL);
            return "+60";
        } else {
            SpHelper.saveData(X3Constent.BASE_SERVICE_URL_SAVE, X3Constent.SERVICE_URL);
            return "+44";
        }
    }

    /**
     * 是否是中国大陆
     * @return
     */
    public static boolean isChina() {
        String areaCode = (String) SpHelper.getData(X3Constent.AREA_CODE, X3Constent.getDefaultAreaCode());
        if("+86".equals(areaCode)) {
            return true;
        }
        return false;
    }

    /**
     * 是否是中国大陆和台湾
     * @return
     */
    public static boolean isChinaAndTw() {
        String areaCode = (String) SpHelper.getData(X3Constent.AREA_CODE, X3Constent.getDefaultAreaCode());
        if("+86".equals(areaCode) || "+886".equals(areaCode)) {
            return true;
        }
        return false;
    }

    /**
     * 获取router服务器
     * @return
     */
    public static String getBaseGeneralUrl() {
        if (BuildConfig.isDebug && !X3StringUtils.isEmpty((String) SpHelper.getData("Debug_Base_Url",""))) {
            return (String) SpHelper.getData("Debug_Base_Url","");
        }
        return BuildConfig.BASE_GENERAL_URL;
    }

    /**
     * 返回H5url
     * @return
     */
    public static String getH5BaseUrl () {
        if (BuildConfig.isDebug && !X3StringUtils.isEmpty((String) SpHelper.getData("Debug_Base_H5_Url",""))) {
            return (String) SpHelper.getData("Debug_Base_H5_Url","");
        }
        return (String) SpHelper.getData(X3Constent.BASE_SERVICE_URL_SAVE, getBaseServiceUrlByAreaCode());
    }

    /**
     * 返回原生hosturl
     * @return
     */
    public static String getNativeHostUrl () {

        if (BuildConfig.isDebug && !X3StringUtils.isEmpty((String) SpHelper.getData("Debug_Base_Url",""))) {
            String host = (String) SpHelper.getData("Debug_Base_Url","");
            int index = host.indexOf("router/");
            String url = host.substring(0,index);
            if (url.contains(":802")){
                url = url.substring(0,url.indexOf(":802"));
            }
            if (url.contains("https://ntestrouter")){
                url = url.replace("ntestrouter","cntest");
            }
            return url  ;
        }
        String ht = getBaseUrlByAreaCode();
        if(ht.contains("/mechanic/api-v1/")){
            ht = ht.replace("/mechanic/api-v1/","");
        }
        return ht ;
    }

    /**
     * 判断是cntest
     * @return
     */
    public static boolean isCnTest(){
        if (getBaseGeneralUrl().contains("ntest")){
            return true;
        }
        return false;
    }

    /**
     * 分享步序图
     * @return
     */
    public static String getShareStepUrl () {
        if (BuildConfig.isDebug && !X3StringUtils.isEmpty((String) SpHelper.getData("Debug_Base_H5_Url",""))) {
            String host = (String) SpHelper.getData("Debug_Base_H5_Url","");
            int index = host.indexOf("mechanic/");
            String url = host.substring(0,index);
            return url + SHARE_STEP_URL;
        }
        String ht = (String) SpHelper.getData(X3Constent.BASE_SERVICE_URL_SAVE, getBaseServiceUrlByAreaCode());
        int index2 = ht.indexOf("mechanic/");
        String url2 = ht.substring(0,index2);
        return url2 + SHARE_STEP_URL;
    }

    /**
     * 分享小程序默认网页
     * @return
     */
    public static String getShareMiniDefaultUrl (int type) {
        if (BuildConfig.isDebug && !X3StringUtils.isEmpty((String) SpHelper.getData("Debug_Base_H5_Url",""))) {
            String host = (String) SpHelper.getData("Debug_Base_H5_Url","");
            int index = host.indexOf("mechanic/");
            String url = host.substring(0,index);
            if (type == 1){
                return url + SHARE_ALONE_MINI_URL;
            }
            return url + SHARE_MINI_URL;
        }
        String ht = (String) SpHelper.getData(X3Constent.BASE_SERVICE_URL_SAVE, getBaseServiceUrlByAreaCode());
        int index2 = ht.indexOf("mechanic/");
        String url2 = ht.substring(0,index2);
        if (type == 1){
            return url2 + SHARE_ALONE_MINI_URL;
        }
        return url2 + SHARE_MINI_URL;
    }

    /**
     * 判断是哪国 用于显示什么性别
     * 0 中国 台湾
     * 1 马来 英国 美国 爱尔兰
     * 2 德国
     * @return
     */
    public static int getCountrySex() {
        String areaCode = (String) SpHelper.getData(X3Constent.AREA_CODE, X3Constent.getDefaultAreaCode());
        if ("+86".equals(areaCode) || "+886".equals(areaCode)) {
            return 0;
        }else if ("+49".equals(areaCode)) {
            return 2;
        }
        return 1;
    }

    /**
     * 0 中国
     * 1 德国
     * 2 全球
     * @return
     */
    public static int isWhichCountry() {
        String area_code = (String) SpHelper.getData(X3Constent.AREA_CODE, "+44");
        if ("+86".equals(area_code)) {
            return 0;
        } else if ("+49".equals(area_code)) {
            return 1;
        }
        return 2;
    }

    /**
     * 判断是哪国 用于显示常用姓氏
     * 0 中国
     * 1 台湾
     * 2 马来西亚
     * 3 英国
     * 4 德国
     * 5 美国
     * @return
     */
    public static int getWhichCountry() {
        String areaCode = (String) SpHelper.getData(X3Constent.AREA_CODE, X3Constent.getDefaultAreaCode());
        switch (areaCode) {
            case "+86":
                return 0;
            case "+886":
                return 1;
            case "+60":
                return 2;
            case "+44":
                return 3;
            case "+49":
                return 4;
            case "+1":
                return 5;
            case "+353":
                return 6;
            default:
                return 3;
        }
    }

    public static int getKeyBoardDelayed(){
        return 300;
    }


    /**
     * 获取当前URL的类型是91还是测试，还是正式
     * 1：正式 V
     * 2：测试 T
     * 3：91 R
     * @return
     */
    public static int getUrlType() {
        if (BuildConfig.isDebug && !X3StringUtils.isEmpty((String) SpHelper.getData("Debug_Base_Url",""))) {
            String url = (String) SpHelper.getData("Debug_Base_Url","");
            if (url.contains("192.168.")){
                return 3;
            } else if (url.startsWith("https://router.autox3.com")){
                return 1;
            }
            return 2;
        }
        return 1;
    }


}
